package com.zr.controller.driverclient;

import com.zr.service.driverclient.MissionService;
import com.zr.utils.AjaxResult;
import com.zr.vo.car.CarInfo;
import com.zr.vo.dispatch.DispatchAbnormalRecord;
import com.zr.vo.dispatch.DispatchTicket;
import com.zr.vo.order.OrderForm;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@RestController
@RequestMapping("/mission")
@CrossOrigin
public class MissionController {
    @Resource
    private MissionService missionService;

    /**
     * 获取登录司机的当前任务
     * @param carInfo
     * @return
     */
    @PostMapping("/getDisList")
    public AjaxResult getDisList(@RequestBody CarInfo carInfo){

        String carNumber=carInfo.getNumber();
        return AjaxResult.success(200,"查询成功", missionService.getDisList(carNumber));
    }

    /**
     * 获取登录司机的历史任务
     * @param carInfo
     * @return
     */
    @PostMapping("/getHisDisList")
    public AjaxResult getHisDisList(@RequestBody CarInfo carInfo){
        String carNumber=carInfo.getNumber();
        return AjaxResult.success(200,"查询成功", missionService.getHisDisList(carNumber));

    }

    /**
     * 修改调度单状态信息
     * @param dispatchTicket
     * @return
     */
    @PostMapping("/editDispatchTicket")
    public AjaxResult editDispatchTicket(@RequestBody DispatchTicket dispatchTicket){

        return AjaxResult.success(200,"修改成功", missionService.editDispatchTicket(dispatchTicket));
    }

    /**
     * 更改订单状态
     * @return
     */
    @PostMapping("/editOrderStatus")
    public AjaxResult editOrderStatus(@RequestBody OrderForm orderForm){
        int a= missionService.editOrderStatus(orderForm);
        //判单是否全部订单完成
        if(a>0&&orderForm.getCurrentStatus().equals("已送达")){
           missionService.editDispatchTicketFinal(orderForm);
        }
        return AjaxResult.success(200,"状态更改成功",null);
    }
    /**
     * 提货后重新获取信息
     * @param dispatchTicket
     * @return
     */
    @PostMapping("/getDisInfo")
    public AjaxResult getDisInfo(@RequestBody DispatchTicket dispatchTicket){
        return AjaxResult.success(200,"更新成功", missionService.getDisInfo(dispatchTicket));
    }

    /**
     * 异常提交
     * @param dispatchAbnormalRecord
     * @return
     */
    @PostMapping("/abnormal")
    public AjaxResult abnormal(@RequestBody DispatchAbnormalRecord dispatchAbnormalRecord){
            return AjaxResult.success(200,"上报成功",missionService.abnormal(dispatchAbnormalRecord));
    }


}
